#include <bits/stdc++.h>
using namespace std;
//#define int long long
int read () {
    int s=0,f=1;
    char t=getchar();
    while ((t>'9'||t<'0')&&t!='-') t=getchar();
    if (t=='-') {
        f=-1;
        t=getchar();
    }
    while (t<='9'&&t>='0') {
        s=s*10+(t-'0');
        t=getchar();
    }
    return s*f;
}
int ans;
int n,m,rl,rv;
int d[100001],v[100001],a[100001];
int p[100001];
struct node {
    int l,r,num,id;
};
bool cmp (node x,node y) {
    return x.num<y.num;
}
node pho[100001];
struct node1 {
    int num,id;
};
bool cmp1 (node1 x,node1 y) {
    return x.num>y.num;
}
node1 pp[100001];
int cntt[100010],h[100001];
int hj (int x) {
    int l=0,r=m;
    while (l<r) {
        int mid=(l+r)>>1;
        if (p[mid]>=x) r=mid;
        else l=mid+1;
    }
    return l;
}
int qq (int x) {
    int l=0,r=m;
    while (l<r) {
        int mid=(l+r+1)>>1;
        if (p[mid]<=x) l=mid;
        else r=mid-1;
    }
    if (l==0) return 1;
    return l;
}
void sol1 () {
    for (int i=1;i<=n;i++) {
        int cl=-114514,cr=-114514;
        if (a[i]==0) {
            if (v[i]>rv) {
                cl=d[i];
                cr=rl;
            }
        }
        if (a[i]>0) {
            cr=rl;
            if (v[i]>rv) {
                cl=d[i];
            }
            if (v[i]==rv) {
                cl=d[i]+1;
            }
            if (v[i]<rv) {
                cl=int(d[i]*1.0+((rv*rv)-(v[i]*v[i]))*1.0/(a[i]*2.0))+1;
            }
        }
        if (a[i]<0) {
            if (v[i]>rv) {
                cl=d[i];
                cr=ceil(d[i]*1.0+((v[i]*v[i])-(rv*rv))*1.0/(abs(a[i])*2.0))-1;
            }
        }
        if (cr>rl) cr=rl;
        if (cl>cr) {
            cl=-114514;
            cr=-114514;
        }
        //cout<<i<<' '<<cl<<' '<<cr<<' '<<'\n';
        pho[i].id=i;
        if(cl==-114514&&cr==-114514) {
            pho[i].l=-1;
            pho[i].r=-1;
            pho[i].num=1145141919;
        }
        else {
            pho[i].l=hj(cl);
            pho[i].r=qq(cr);
            pho[i].num=pho[i].r-pho[i].l+1;
            if (pho[i].l>pho[i].r) {
                pho[i].l=-1;
                pho[i].r=-1;
                pho[i].num=0;
            }
            else {
                cntt[pho[i].l]++;
                cntt[pho[i].r+1]--;
            }
        }
        if (pho[i].l==-1) ans--;
        //cout<<pho[i].l<<' '<<pho[i].r<<'\n';
    }
}
int sol2 () {
    int cont=0;
    int ress=0;
    for (int i=1;i<=m;i++) {
        ress++;
        for (int j=1;j<=ans;j++) {
            if (pho[j].l<=pp[i].id&&pho[j].r>=pp[i].id) {
                if (h[j]==0) {
                    h[j]=1;
                    cout++;
                }
            }
        }
        if (cout==ans) break;
    }
    return ress;
}
signed main () {
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T=read();
    while (T--) {
        n=read();
        m=read();
        rl=read();
        rv=read();
        for (int i=1;i<=n;i++) {
            d[i]=read();
            v[i]=read();
            a[i]=read();
            h[i]=0;
        }
        for (int i=1;i<=m;i++) {
            p[i]=read();
        }
        sort(p+1,p+1+n);
        ans=n;
        sol1();
        for (int i=1;i<=m;i++) {
            pp[i].id=i;
            pp[i].num=pp[i-1].num+cntt[i];
        }
        //sort(pho+1,pho+1+n,cmp);
        sort(pp+1,pp+1+m,cmp1);
        cout<<ans<<' '<<m-sol2()<<'\n';
    }
    return 0;
}